package com.wza.designPattern.PrototypePattern;

import java.util.HashMap;

/**
 * <一句话功能简述>
 * <p>
 * <功能详细描述>
 *
 * @author weizhian
 * @version [版本号, 2018/11/20]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class ShapeCache
{
    private static HashMap<String, Shape> shapeHashMap = new HashMap<>();

    public static Shape getShape(String id)
    {
        return (Shape) shapeHashMap.get(id).clone();
    }

    // 对每种形状都运行数据库查询，并创建该形状
    // shapeMap.put(shapeKey, shape);
    // 例如，我们要添加三种形状
    public static void loadCache() {
        Circle circle = new Circle();
        circle.setId("1");
        shapeHashMap.put(circle.getId(),circle);

        Square square = new Square();
        square.setId("2");
        shapeHashMap.put(square.getId(),square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("3");
        shapeHashMap.put(rectangle.getId(),rectangle);
    }
}
